var http = require('http');
var url  = require('url');
var querystring = require('querystring');
var start = require('./start');
var show = require('./show');
var upfile = require('./upfile');
var upload = require('./upload');
var showimg = require('./showimg');

// demo
var person_page = require('./demo/person_page');
var person_edit = require('./demo/person_edit');

// api
var init = require('./init');

// file
var file = require('./file');

// robot
var robot = require('./demo/robot');

http.createServer(function(request, response) {

    var pathname = url.parse(request.url).pathname;

    var routeurl = {
        '/': start.start,
        '/show': show.show,
        '/upfile': upfile.upfile,
        '/upload': upload.upload,
        '/showimg': showimg.showimg,
        // demo
        '/person': person_page.html,
        '/person_edit': person_edit.result,
        // api
        '/init': init.init,
        // file
        '/file': file.file,
        '/floder': file.floder,
        // 爬虫
        '/robot': robot.robot
    };
    
    if(typeof routeurl[pathname] === 'function') {
        routeurl[pathname](request, response);
    } else {
        console.log('404 not found');
        response.end();
    }

}).listen(3000);

console.log('server has started...');